package shop.controller.manage.dataAnalyse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import shop.controller.manage.weightrecord.WeightrecordAction;
import shop.core.common.dao.page.PagerModel;
import shop.services.manage.weightrecord.WeightrecordService;
import shop.services.manage.weightrecord.bean.Weightrecord;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by wzl on 2018/4/27.
 * 过磅记录数据分析
 */
@Controller
@RequestMapping("/manage/dataAnalyse/")
public class DataAnalyseAction {
    private static final Logger logger = LoggerFactory.getLogger(WeightrecordAction.class);
    @Autowired
    private WeightrecordService weightrecordService;
    public WeightrecordService getService() {
        return weightrecordService;
    }

    /**
     * 分页查询采砂场数据总数
     *
     * @param request 请求
     * @param weightrecord    对象参数
     * @return 分页数据模型
     */
    @RequestMapping("selectSandpitPage")
    @ResponseBody
    public PagerModel selectSandpitPage(HttpServletRequest request, Weightrecord weightrecord) {
        int offset = 0;
        int pageSize = 10;
        int start = Integer.parseInt(request.getParameter("start"));
        int length = Integer.parseInt(request.getParameter("length"));
        if (start > 0)
            offset = start;
        if (length > 0)
            pageSize = length;
        weightrecord.setOffset(offset);
        weightrecord.setPageSize(pageSize);
        PagerModel pager = weightrecordService.selectSandpitPage(weightrecord);
        pager.setRecordsTotal(pager.getTotal());
        pager.setRecordsFiltered(pager.getTotal());
        return pager;
    }

    /**
     * 分页查询采砂场数据详情
     *
     * @param request 请求
     * @param weightrecord    对象参数
     * @return 分页数据模型
     */
    @RequestMapping("selectSandpitDetailPage")
    @ResponseBody
    public PagerModel selectSandpitDetailPage(HttpServletRequest request, Weightrecord weightrecord) {
        int offset = 0;
        int pageSize = 10;
        int start = Integer.parseInt(request.getParameter("start"));
        int length = Integer.parseInt(request.getParameter("length"));
        if (start > 0)
            offset = start;
        if (length > 0)
            pageSize = length;
        weightrecord.setOffset(offset);
        weightrecord.setPageSize(pageSize);
        PagerModel pager = weightrecordService.selectSandpitDetailPage(weightrecord);
        pager.setRecordsTotal(pager.getTotal());
        pager.setRecordsFiltered(pager.getTotal());
        return pager;
    }

    /**
     * 分页查询车辆数据总数
     *
     * @param request 请求
     * @param weightrecord    对象参数
     * @return 分页数据模型
     */
    @RequestMapping("selectCartPage")
    @ResponseBody
    public PagerModel selectCartPage(HttpServletRequest request, Weightrecord weightrecord) {
        int offset = 0;
        int pageSize = 10;
        int start = Integer.parseInt(request.getParameter("start"));
        int length = Integer.parseInt(request.getParameter("length"));
        if (start > 0)
            offset = start;
        if (length > 0)
            pageSize = length;
        weightrecord.setOffset(offset);
        weightrecord.setPageSize(pageSize);
        PagerModel pager = weightrecordService.selectCartPage(weightrecord);
        pager.setRecordsTotal(pager.getTotal());
        pager.setRecordsFiltered(pager.getTotal());
        return pager;
    }

    /**
     * 分页查询车辆数据详情
     *
     * @param request 请求
     * @param weightrecord    对象参数
     * @return 分页数据模型
     */
    @RequestMapping("selectCartDetailPage")
    @ResponseBody
    public PagerModel selectCartDetailPage(HttpServletRequest request, Weightrecord weightrecord) {
        int offset = 0;
        int pageSize = 10;
        int start = Integer.parseInt(request.getParameter("start"));
        int length = Integer.parseInt(request.getParameter("length"));
        if (start > 0)
            offset = start;
        if (length > 0)
            pageSize = length;
        weightrecord.setOffset(offset);
        weightrecord.setPageSize(pageSize);
        PagerModel pager = weightrecordService.selectCartDetailPage(weightrecord);
        pager.setRecordsTotal(pager.getTotal());
        pager.setRecordsFiltered(pager.getTotal());
        return pager;
    }

    /**
     * 分页查询品名数据总数
     *
     * @param request 请求
     * @param weightrecord    对象参数
     * @return 分页数据模型
     */
    @RequestMapping("selectProductPage")
    @ResponseBody
    public PagerModel selectProductPage(HttpServletRequest request, Weightrecord weightrecord) {
        int offset = 0;
        int pageSize = 10;
        int start = Integer.parseInt(request.getParameter("start"));
        int length = Integer.parseInt(request.getParameter("length"));
        if (start > 0)
            offset = start;
        if (length > 0)
            pageSize = length;
        weightrecord.setOffset(offset);
        weightrecord.setPageSize(pageSize);
        PagerModel pager = weightrecordService.selectProductPage(weightrecord);
        pager.setRecordsTotal(pager.getTotal());
        pager.setRecordsFiltered(pager.getTotal());
        return pager;
    }

    /**
     * 分页查询品名数据详情
     *
     * @param request 请求
     * @param weightrecord    对象参数
     * @return 分页数据模型
     */
    @RequestMapping("selectProductDetailPage")
    @ResponseBody
    public PagerModel selectProductDetailPage(HttpServletRequest request, Weightrecord weightrecord) {
        int offset = 0;
        int pageSize = 10;
        int start = Integer.parseInt(request.getParameter("start"));
        int length = Integer.parseInt(request.getParameter("length"));
        if (start > 0)
            offset = start;
        if (length > 0)
            pageSize = length;
        weightrecord.setOffset(offset);
        weightrecord.setPageSize(pageSize);
        PagerModel pager = weightrecordService.selectProductDetailPage(weightrecord);
        pager.setRecordsTotal(pager.getTotal());
        pager.setRecordsFiltered(pager.getTotal());
        return pager;
    }

}
